package itdep.domain;

import ga.i18n.TranslatableEntity;
import ga.i18n.Translation;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Ivan Khalopik
 * @version $Revision: 9 $ $Date: 2010-06-15 22:29:57 +0000 (Tue, 15 Jun 2010) $
 */
@MappedSuperclass
public class CodedEntity extends IisEntity implements TranslatableEntity {

	@Column(name = "CODE", nullable = false)
	private String code;

	@Transient
	private final String translationType;

	@Transient
	private final Collection<String> translationVariants;

	@Transient
	private final Map<String, Translation> translations = new HashMap<String, Translation>();

	public CodedEntity(String translationType, Collection<String> translationVariants) {
		this.translationType = translationType;
		this.translationVariants = translationVariants;
	}

	protected CodedEntity(String basename, TranslationType translationType) {
		this(basename, translationType.getVariants());
	}

	public String getTranslationType() {
		return translationType;
	}

	public String getTranslationCode() {
		return code;
	}

	public Collection<String> getTranslationVariants() {
		return translationVariants;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Map<String, Translation> getTranslations() {
		return translations;
	}

	public void setTranslations(Map<String, ga.i18n.Translation> translations) {
		this.translations.clear();
		this.translations.putAll(translations);
	}
}